//
//  NSModelDetailLikePassView.m
//  Meboo
//
//  Created by kyo on 2024/3/18.
//

#import "NSModelDetailLikePassView.h"
#import "NSFlashChatViewController.h"
#import "NSVipPopView.h"
@interface NSModelDetailLikePassView()
//like
@property(nonatomic,strong) UIButton *likeBtn;
//pass
@property(nonatomic,strong) UIButton *passBtn;
//fc
@property(nonatomic,strong) UIButton *fcBtn;

@property(nonatomic,strong) NSVipPopView *vipPopView;
@end

@implementation NSModelDetailLikePassView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setModel:(NSUserInfoModel *)model {
    _model = model;
    //根据来源不同 处理三个按钮不同展示
    if (self.modelStyle == HomeModelDetail) {
        //home 三个都展示
        self.likeBtn.hidden = NO;
        self.passBtn.hidden = NO;
        self.fcBtn.hidden = NO;
    } else if (self.modelStyle == WLMModelDetail) {
        //wlm fcBtn不展示
        self.likeBtn.hidden = NO;
        self.passBtn.hidden = NO;
        self.fcBtn.hidden = YES;
    } else {
        //chat 表明已经建联 三个都不展示
        self.likeBtn.hidden = YES;
        self.passBtn.hidden = YES;
        self.fcBtn.hidden = YES;
    }
}

//modelStyle
- (void)setModelStyle:(ModelDetailStyle)modelStyle {
    _modelStyle = modelStyle;
}

#pragma mark - Action
//跳转fc页面
- (void)flashChatAction {
    NSFlashChatViewController *fcViewController = [NSFlashChatViewController new];
    fcViewController.style = HomeProfileStyle;
    fcViewController.model = self.model;
    [self.currentViewController.navigationController pushViewController:fcViewController animated:YES];
    /**
     埋点
     点击Flash chat Home_Profile_Flashchat
     */
    [[NSIOApiManager sharedManager] setIOWithEventName:@"Home_Profile_Flashchat"];
}

//根据不同来源的枚举值,发送通知,父页面接受通知作出响应
- (void)likePassAction:(UIButton *)button {
    
    if (self.modelStyle == HomeModelDetail) {
        //home 1:like 4:pass
        NSNotification *notify = [NSNotification notificationWithName:HOME_MODELDETAIL_LIKEPASS object:[NSString stringWithFormat:@"%ld",button.tag]];
        [MBNotificationCenter postNotification:notify];//中心调方法，内容是参数
        [self.currentViewController.navigationController popViewControllerAnimated:YES];
    } else if (self.modelStyle == WLMModelDetail) {
        NSNotification *notify = [NSNotification notificationWithName:WLM_MODELDETAIL_LIKEPASS object:[NSString stringWithFormat:@"%ld",button.tag == 4 ? 2 : button.tag]];
        [MBNotificationCenter postNotification:notify];//中心调方法，内容是参数
        [self.currentViewController.navigationController popViewControllerAnimated:YES];
    }
    
    /**
     埋点
     点击喜欢 chat Home_Profile_Like
     点击不喜欢 Home_Profile_Pass
     */
    [[NSIOApiManager sharedManager] setIOWithEventName:button.tag == 1 ? @"Home_Profile_Like" : @"Home_Profile_Pass"];
}

#pragma mark - UI
- (void)setupUI {
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.likeBtn];
    [self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.height.mas_equalTo(MBHeightScale(75));
    }];
    
    [self addSubview:self.fcBtn];
    [self.fcBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.likeBtn.mas_right).offset(MBWidthScale(35));
        make.width.height.mas_equalTo(MBHeightScale(75));
        make.centerY.equalTo(self);
    }];
    
    [self addSubview:self.passBtn];
    [self.passBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.likeBtn.mas_left).offset(MBWidthScale(-35));
        make.width.height.mas_equalTo(MBHeightScale(75));
        make.centerY.equalTo(self);
    }];
    
    //pop
    [self vipPopView];
}

#pragma mark - Setter && Getter
- (UIButton *)likeBtn {
    if (!_likeBtn) {
        _likeBtn = [UIButton new];
        [_likeBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_likeBtn setBackgroundImage:ImageWithName(@"model_detail_like") forState:0];
//        [_likeBtn setBackgroundImage:ImageWithName(@"model_detail_like") forState:0];
        _likeBtn.tag = 1;
        [_likeBtn addTarget:self action:@selector(likePassAction:) forControlEvents:UIControlEventTouchUpInside];
        _likeBtn.hidden = YES;
    }
    return _likeBtn;
}

- (UIButton *)passBtn {
    if (!_passBtn) {
        _passBtn = [UIButton new];
        [_passBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_passBtn setBackgroundImage:ImageWithName(@"model_detail_pass") forState:0];
//        [_passBtn setImage:ImageWithName(@"model_detail_pass") forState:0];
        _passBtn.tag = 4;
        [_passBtn addTarget:self action:@selector(likePassAction:) forControlEvents:UIControlEventTouchUpInside];
        _passBtn.hidden = YES;
    }
    return _passBtn;
}

- (UIButton *)fcBtn {
    if (!_fcBtn) {
        _fcBtn = [UIButton  new];
        [_fcBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_fcBtn setBackgroundImage:ImageWithName(@"model_detail_fc") forState:0];
//        [_fcBtn setImage:ImageWithName(@"model_detail_fc") forState:0];
        [_fcBtn addTarget:self action:@selector(flashChatAction) forControlEvents:UIControlEventTouchUpInside];
        _fcBtn.hidden = YES;
    }
    return _fcBtn;
}

- (NSVipPopView *)vipPopView {
    if (!_vipPopView) {
        _vipPopView = [NSVipPopView new];
    }
    return _vipPopView;
}
@end
